package org.afk.tools.log;

import java.text.*;
import java.util.*;

public class ConsoleErrorHandler implements ErrorHandler
{
	private boolean debug;
	private final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS");

	private String d()
	{
		return this.dateFormat.format(new Date()) + " ";
	}

	@Override
	public void debug(final String message)
	{
		if (this.debug)
			System.out.println(d() + message);
	}

	@Override
	public void info(final String message)
	{
		System.out.println(d() + message);
	}

	public boolean isDebug()
	{
		return this.debug;
	}

	public void setDebug(final boolean debug)
	{
		this.debug = debug;
	}

	@Override
	public void warning(final String message)
	{
		System.out.println(d() + message);

	}

	@Override
	public void warning(final String message, final Throwable t)
	{
		System.out.println(d() + message);
		t.printStackTrace(System.out);
		if (t.getCause() != null)
			warning(" cause: ", t.getCause());
	}

	@Override
	public void warning(final Throwable t)
	{
		warning(t.getLocalizedMessage(), t);
	}

}
